import {getCookie} from "../../utils/cookie";
import {file_w, getObject, getQuery, query_options} from "../../utils/databaseUtil";
import {getLocal} from "../../utils/local";

export async function get_profile() {
    var user = getCookie("app.login_user")
    var q = getQuery('user')
    q = query_options(q, ['objectId', '==', user.objectId])
    q.include('image')
    var r = await q.first().then(res => res.toJSON())
    return r
}

export async function update_user_image(image) {
    var user = getCookie("app.login_user")
    var User = getObject('user')
    User.id = user.objectId
    var image_w = file_w(image.objectId)
    User.set('image', image_w)
    var result = await User.save().then(res => res.toJSON())
    return result
}